<template>
  <div class="content-card">
    <div class="card-header d-flex justify-content-between align-items-center">
      <h2><i class="fas fa-comments mr-2"></i>留言管理</h2>
      <router-link to="/message/add" class="btn btn-primary">
        <i class="fas fa-plus-circle mr-1"></i>新建留言
      </router-link>
    </div>
    <div class="card-body">
      <div class="table-responsive">
        <table class="table table-hover">
          <thead>
            <tr>
              <th>标题</th>
              <th>内容</th>
              <th>状态</th>
              <th>回复</th>
              <th>创建者</th>
              <th>创建时间</th>
              <th>操作</th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="message in messages" :key="message.id">
              <td>{{ message.title }}</td>
              <td>{{ message.content.length > 50 ? message.content.substring(0, 50) + '...' : message.content }}</td>
              <td>{{ message.status }}</td>
              <td>{{ message.reply ? message.reply.length > 50 ? message.reply.substring(0, 50) + '...' : message.reply : '-' }}</td>
              <td>{{ message.creator.username }}</td>
              <td>{{ formatDate(message.createTime) }}</td>
              <td>
                <router-link :to="`/message/edit/${message.id}`" class="btn btn-sm btn-info">
                  <i class="fas fa-edit"></i>
                </router-link>
                <button @click="deleteMessage(message.id)" class="btn btn-sm btn-danger"
                        onclick="return confirm('确定要删除这条留言吗？')">
                  <i class="fas fa-trash"></i>
                </button>
              </td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'MessageList',
  data() {
    return {
      messages: []
    }
  },
  methods: {
    formatDate(date) {
      return new Date(date).toLocaleString('zh-CN', {
        year: 'numeric',
        month: '2-digit',
        day: '2-digit',
        hour: '2-digit',
        minute: '2-digit'
      })
    },
    deleteMessage(id) {
      if (confirm('确定要删除这条留言吗？')) {
        // TODO: 实现删除留言的API调用
        console.log('删除留言:', id)
      }
    }
  },
  created() {
    // TODO: 实现获取留言列表的API调用
    this.messages = [
      {
        id: 1,
        title: '关于文化遗产保护的建议',
        content: '我想就文化遗产保护提出几点建议...',
        status: '未回复',
        reply: '',
        creator: {
          username: '用户1'
        },
        createTime: '2025-06-01 10:00:00'
      }
      // ... 其他示例数据
    ]
  }
}
</script>

<style scoped>
/* 卡片样式 */
.content-card {
  margin: 20px;
  border-radius: 15px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  background: linear-gradient(145deg, #ffffff 0%, #f8f9fa 100%);
}

/* 卡片头部样式 */
.card-header {
  background-color: #2c3e50;
  color: white;
  border-bottom: none;
  padding: 1.5rem 2rem;
  border-radius: 15px 15px 0 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header h2 {
  margin: 0;
  font-size: 1.8rem;
  font-weight: 600;
  display: flex;
  align-items: center;
}

.card-header i {
  color: #3498db;
  margin-right: 0.5rem;
  font-size: 1.2rem;
}

/* 添加按钮样式 */
.btn-primary {
  background-color: #3498db;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-weight: 500;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-primary:hover {
  background-color: #2980b9;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(52, 152, 219, 0.2);
}

/* 表格样式 */
.table {
  margin-bottom: 0;
  background: white;
}

.table th {
  background-color: #f8f9fa;
  border: none;
  font-weight: 600;
  color: #333;
  padding: 1rem;
  font-size: 0.95rem;
}

.table td {
  border: none;
  vertical-align: middle;
  padding: 1rem;
  font-size: 0.95rem;
  color: #333;
}

.table tr:hover {
  background-color: rgba(52, 152, 219, 0.05);
}

/* 状态标签样式 */
.status-tag {
  padding: 0.35rem 0.75rem;
  border-radius: 12px;
  font-size: 0.875rem;
  font-weight: 500;
  text-align: center;
}

.status-unreplied {
  background-color: #e74c3c;
  color: white;
}

.status-replied {
  background-color: #2ecc71;
  color: white;
}

/* 操作按钮样式 */
.btn-sm {
  padding: 0.4rem 0.8rem;
  font-size: 0.875rem;
  border-radius: 6px;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.btn-sm i {
  font-size: 0.875rem;
}

.btn-info {
  background-color: #3498db;
  border: none;
}

.btn-danger {
  background-color: #e74c3c;
  border: none;
}

.btn-info:hover,
.btn-danger:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

/* 时间样式 */
.timestamp {
  font-size: 0.875rem;
  color: #6c757d;
}

/* 间距类 */
.mr-2 {
  margin-right: 0.75rem;
}

.mr-1 {
  margin-right: 0.5rem;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .card-header {
    flex-direction: column;
    gap: 1rem;
  }
  
  .card-header h2 {
    font-size: 1.5rem;
  }
  
  .btn-primary {
    padding: 0.6rem 1.2rem;
    font-size: 0.9rem;
  }
  
  .table th,
  .table td {
    padding: 0.8rem;
    font-size: 0.875rem;
  }
}
</style>
